//
//  baseTableViewController.swift
//  weibo
//
//  Created by 张衡 on 15/7/29.
//  Copyright © 2015年 张衡. All rights reserved.
//

import UIKit

class baseTableViewController: UITableViewController, VisitorLoginViewDelegate {
    
    /// 用户登录标记
    var userLogon = UserAccount.userLogon // false //UserAccount.loadAccount() != nil // 能返回json表登录成功归档过，已登录过
    
    /// 访客视图
    var visitorView: VisitorLoginView? // 这个问号会报错
    
    override func loadView() {
        
        // 根据用户是否登录判断是否替换跟视图
        userLogon ? super.loadView() : setupVisitorView()
    }
    
    /// 设置访客视图
    private func setupVisitorView() {
        visitorView = VisitorLoginView()
        
        visitorView?.delegate = self
        
        view = visitorView
        
        // 设置状态栏
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillLogin")
        
    }
    
    func visitorLoginViewWillRegister() {
        // print("注册")
    }
    
    func visitorLoginViewWillLogin() {
        let nav = UINavigationController(rootViewController: OAuthViewController())
        
        presentViewController(nav, animated: true, completion: nil)
    }

}
